class Solution {
public:
    int search(vector<int>& nums, int target) {
        if(target<nums[0]||target>nums[nums.size()-1])return -1;
        int left=0;int right=nums.size();
        while(left<right)
        {
            int mid=left+(right-left)/2;
            if(nums[mid]>=target)
            right=mid;
            else if(nums[mid]<target)
            left=mid+1;
        }
        if(nums[left]!=target)return -1;
        return left;
    }
};
